package gold.digger;

import gold.utils.InputUtil;

import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC630 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int scheduleCourse(int[][] courses) {
            Arrays.sort(courses, (a, b) -> a[1] - b[1]);
            PriorityQueue<Integer> q = new PriorityQueue<>(Comparator.reverseOrder());
            int sum = 0;
            for (int[] course : courses) {
                int d = course[0], e = course[1];
                sum += d;
                q.add(d);
                if (sum > e) sum -= q.poll();
            }
            return q.size();
        }
    }

    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[1,2,3]");
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC630 an = new LC630();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
